
<div class="sidebar" id="sidebar">
    <script type="text/javascript">
        try {
            ace.settings.check('sidebar', 'fixed')
        } catch (e) {
        }
    </script>

    <div class="sidebar-shortcuts" id="sidebar-shortcuts">
        <div class="sidebar-shortcuts-large" id="sidebar-shortcuts-large">
            <button class="btn btn-success">
                <i class="icon-signal"></i>
            </button>

            <button class="btn btn-info">
                <i class="icon-pencil"></i>
            </button>

            <button class="btn btn-warning">
                <i class="icon-group"></i>
            </button>

            <button class="btn btn-danger">
                <i class="icon-cogs"></i>
            </button>
        </div>

        <div class="sidebar-shortcuts-mini" id="sidebar-shortcuts-mini">
            <span class="btn btn-success"></span>

            <span class="btn btn-info"></span>

            <span class="btn btn-warning"></span>

            <span class="btn btn-danger"></span>
        </div>
    </div>
    <!-- #sidebar-shortcuts -->

    <ul id="nav-list" class="nav nav-list">
        <li class="active">
            <a href="${base}/admin/main">
                <i class="icon-dashboard"></i>
                <span class="menu-text"> 控制台 </span>
            </a>
        </li>
        <!-- jquery dynamic add menu -->
    </ul>
    <!-- /.nav-list -->

    <div class="sidebar-collapse" id="sidebar-collapse">
        <i class="icon-double-angle-left" data-icon1="icon-double-angle-left" data-icon2="icon-double-angle-right"></i>
    </div>

    <script type="text/javascript">
        try {
            ace.settings.check('sidebar', 'collapsed')
        } catch (e) {
        }
    </script>
</div>
<script type="text/javascript">


    $(document).ready(function () {
        $.post("${base}/admin/resource/list",
                {},
                function (data) {
                    html = appendMenu(data.resources);

                    $("#nav-list").append(html);

                },
                "json");
    });
    /**
     * 组装菜单
     * @param resource
     */
    function appendMenu(resources) {

        html = '';

        $.each(resources, function (index,item) {

            if (item.children.length > 0) {//有子节点

                html += '<li>'
                        + '  <a href="#" class="dropdown-toggle">'
                        + '    <i class="'+item.iconClass+'"></i>'
                        + '    <span class="menu-text"> ' + item.name + ' </span>'
                        + '    <b class="arrow icon-angle-down"></b>'
                        + '  </a>'
                        + '  <ul class="submenu">'
                        + appendMenu(item.children)
                        + '  </ul>'
                        + '</li>';
            } else {//无子节点
                html += '<li>'
                        + '   <a href="' + item.url + '">'
                        + '     <i class="'+item.iconClass+'"></i>'
                        + '     <span class="menu-text">'+item.name+'</span>'
                        + '  </a>'
                        + '</li>';
            }
        });

        return html;

    }
</script>